﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace WMH_Project
{
    public class CommQueue<T>
    {
        private readonly object queueLock = new object();
        private Queue<T> queue;

        public CommQueue()
        {
            queue = new Queue<T>();
            queueLock = new Object();
        }

        public void Enqueue(T comm)
        {
            lock (queueLock)
            {
                queue.Enqueue(comm);
                Monitor.Pulse(queueLock);
            }
        }

        public Queue<T> Dequeue(int stan)
        {
            Queue<T> result;
            lock (queueLock)
            {
                while (queue.Count == 0 && stan != 1)
                    Monitor.Wait(queueLock);
                result = queue;
                queue = new Queue<T>();
            }
            return result;
        }
    }
}
